wxapp.logic.appCenter = {
    boot: function() {
        tywx.NotificationCenter.listen(tywx.EventType.EVT_APP_RUN, this.onAppRun, this), 
        tywx.NotificationCenter.listen(tywx.EventType.EVT_APP_AUTHOR_AFTER, this.onAuthorAfter, this), 
        tywx.NotificationCenter.listen(tywx.EventType.EVT_USER_INFO, this.onAppLogicSuccess, this), 
        tywx.NotificationCenter.listen(tywx.EventType.EVT_APP_TCP_OPEN, this.onTcpOpen, this), 
        tywx.NotificationCenter.listen(tywx.EventType.EVT_APP_TCP_CLOSE, this.onTcpClose, this), 
        tywx.NotificationCenter.listen(tywx.EventType.EVT_APP_TCP_CLOSE, this.onTcpError, this), 
        this.sw = new wxapp.ClsLib.WxStopwatch(), this.totalSw = new wxapp.ClsLib.WxStopwatch(), 
        this.donwloadType = 0, this.downloadState = 1, this.author = !1, this.download = !1, 
        this.enterLobbyCount = 0, this.launchOption = !1, this.moduleKey = "lobby", this.userInfoCount = 0, 
        this.download_error_count = 0, this.login_ok = !1;
    },
    onAppRun: function() {
        if (this.sw.start(), this.totalSw.start(), wxapp.debugHelloWorld) cc.director.runScene(new wxfish.ClsLib.WxHelloWorld()); else {
            var e = this;
            cc.loader.load(res.getArray(res.loading), function() {
                tywx.NotificationCenter.ignore(tywx.EventType.EVT_APP_RUN, e.onAppRun, e), e.sw.tlog("app", "加载app loading资源"), 
                wxfish.ClsLib.LoadingScene.show(), e.checkWxVersion() && (e.setDevicePixelRatio(), 
                wxapp.logic.share.initVideo(), wx.onError(function(e) {
                    var t = new Date(), o = "userId:" + tywx.UserInfo.userId + "time:" + t.toDateString() + " " + t.toTimeString() + ";" + e.message;
                    tywx.BiLog.uploadLogTimely(o);
                }), wx.onMemoryWarning(function(e) {
                    newfish.bilog.clickStat(newfish.bilog.clickStatEventType_MemoryWarning);
                }), wxapp.logic.update.checkUpdate(), wxapp.logic.author.init(), e.sw.start(), wxapp.logic.networkCenter.boot(), 
                wxapp.model.init(), wxapp.model.sceneInfo.setUiState(wxapp.model.sceneInfo.UI_STATE.UI_STATE_LOADING1), 
                wxfish.wxFileManager = new wxfish.WxFileManager(), wxfish.downloader = new wxfish.Downloader(), 
                wxapp.model.loading.initLocalInfo(), e.sw.tlog("app", "初始化一些资源"), wxapp.model.sceneInfo.startLaunchOption(), 
                e.sw.tlog("app", "路由启动参数"), wxapp.debugLocalRes ? e.donwloadType = 2 : (wxapp.model.loading.disposeLoaclInfo(), 
                e.sw.tlog("app", "处理Major版本号,删除本地缓存文件"), wxapp.model.loading.checkResInfo(e.moduleKey).length > 0 ? e.donwloadType = 1 : e.donwloadType = 2, 
                e.sw.tlog("app", "checkResInfo")), e.sw.start(), tywx.NotificationCenter.listen(tywx.EventType.EVT_LOADING_DOWNLOAD_FINISH, e._onDownloadResFinish, e), 
                tywx.NotificationCenter.listen(tywx.EventType.EVT_LOADING_DOWNLOAD_PROGRESS, e._onDownloadResProgress, e), 
                1 == e.donwloadType ? (newfish.bilog.clickStat(newfish.bilog.clickStatEventType_AppStart_1), 
                wxapp.model.loading.startDownloadModule(e.moduleKey)) : (newfish.bilog.clickStat(newfish.bilog.clickStatEventType_AppStart_2), 
                e.loadRes()));
            });
        }
    },
    onAuthorAfter: function() {
        if (tywx.NotificationCenter.ignore(tywx.EventType.EVT_APP_AUTHOR_AFTER, this.onAuthorAfter, this), 
        !this.download && (wxfish.ClsLib.LoadingScene.scene_enable = !0, wxfish.ClsLib.LoadingScene.secen_ready)) try {
            wxfish.ClsLib.LoadingScene.scene.loadingNode.enableProgress();
        } catch (e) {}
        this.author = !0, this.startNext();
    },
    _onDownloadResProgress: function(e) {
        this.processProgress(e);
    },
    _onDownloadResFinish: function(e) {
        var t = this;
        e ? (this.downloadState = 2, this.sw.tlog("app", "下载资源"), wxapp.appData.firstDonwloadSuccess = 2, 
        this.loadRes()) : ++this.download_error_count > 4 ? (this.download_error_count = 0, 
        wxapp.logic.socket.connectStatus != wxapp.logic.socket.CONNECT_STATUS_ERROR && wxapp.logic.socket.connectStatus != wxapp.logic.socket.CONNECT_STATUS_CLOSE && wxapp.tools.bilog.clickStat(tywx.clickStatEventType.clickStatEventType_load_error1), 
        wx.showModal({
            title: "提示",
            content: "当前网络状况不佳，请检查网络连接后重试。",
            showCancel: !1,
            confirmText: "重试",
            success: function(e) {
                wxapp.model.loading.startDownloadModule(t.moduleKey);
            },
            fail: function() {
                wxapp.model.loading.startDownloadModule(t.moduleKey);
            }
        })) : setTimeout(function() {
            wxapp.model.loading.startDownloadModule(t.moduleKey);
        }, 500);
    },
    loadRes: function() {
        newfish.bilog.clickStat(newfish.bilog.clickStatEventType_AppStart_3);
        var e = this;
        window.wx && newfish.loader.load("common-trigger-finish", [ "newfish.StageLoading" ], {
            trigger: function(t, o, n) {
                var i = n / o * 100 | 0;
                i = Math.min(i, 100), i = Math.max(1, i), e.processProgress(i);
            },
            triggerTarget: this,
            cb: function() {
                e.sw.tlog("app", "加载资源"), e.download = !0, e.startNext();
            },
            cbTargget: this
        });
    },
    processProgress: function(e) {
        if (wxfish.ClsLib.LoadingScene.secen_ready && wxfish.ClsLib.LoadingScene.scene && wxfish.ClsLib.LoadingScene.scene.loadingNode) {
            var t = wxfish.ClsLib.LoadingScene.scene.loadingNode;
            1 == this.donwloadType ? 1 == this.downloadState ? t.updateProgress(.95 * e) : t.updateProgress(95 + .05 * e) : t.updateProgress(e);
        }
    },
    startNetwork: function() {
        wxapp.logic.networkCenter.login();
    },
    onTcpOpen: function(e) {
        this.userInfoCount = 0, wxapp.SendMsg.bindUser(e);
    },
    onTcpClose: function() {
        this.login_ok = !1;
    },
    onTcpError: function() {
        this.login_ok = !1;
    },
    onAppLogicSuccess: function(e) {
        newfish.InviteRoomId = null, this.userInfoCount++;
        var t = !1, o = !1, n = [], i = e;
        hall.ME.parseUserInfo(i, function(e) {
            if (e) {
                var i = e.split(".");
                "0" == i[0] && "0" == i[1] && "0" == i[2] && "0" == i[3] ? wxapp.model.sceneInfo.getUiState() != wxapp.model.sceneInfo.UI_STATE.UI_STATE_LOBBY && (t = !0) : i[0] == newfish.gameId && "0" != i[1] && (o = !0, 
                n = [ parseInt(i[1]), parseInt(i[2]) ]);
            }
        }), ty.NotificationCenter.trigger(ty.EventType.UPDATE_UER_INFO, hall.ME), 1 == this.userInfoCount && (wxapp.appData.firstLoadSuccess ? (this.login_ok = !0, 
        this.checkSceneInfoStartUp(function(e, t, n, i, a) {
            wxapp.model.sceneInfo.shareClick = i ? {
                shareId: i,
                shareUserId: a
            } : {
                shareId: 0,
                shareUserId: a
            }, o && newfish.model && newfish.model.table && (newfish.model.table.tableId !== n || newfish.model.table.roomId !== t) && (newfish.model.table.noLeave = !0, 
            newfish.msgFactory.sendTableLeave(), cc.error("leave-------------1")), newfish.InviteRoomId = n, 
            newfish.msgFactory.sendQuickStart(t, n);
        }, function(e, t, i, a) {
            if (t && (wxapp.model.sceneInfo.shareClick = i ? {
                shareId: i,
                shareUserId: a
            } : {
                shareId: 0,
                shareUserId: a
            }), o) return wxapp.model.sceneInfo.commitCacheParam(), void setTimeout(function() {
                newfish.msgFactory.sendQuickStart(n[0], n[1]);
            }, 300);
            wxapp.model.sceneInfo.getUiState() == wxapp.model.sceneInfo.UI_STATE.UI_STATE_LOBBY || wxapp.model.sceneInfo.getUiState() == wxapp.model.sceneInfo.UI_STATE.UI_STATE_LOADING1 || newfish.evtCenter.trigger(newfish.evts.EVT_STAGE_REPLACE, newfish.StageLobby);
        })) : (wxapp.appData.firstLoadCount++, this.sw.tlog("app", "网络连接"), this.totalSw.tlog("app", "总耗时"), 
        wxapp.model.sceneInfo.printInfo(), this.login_ok = !0, wxapp.model.sceneInfo.setUiState(wxapp.model.sceneInfo.UI_STATE.UI_STATE_ORTHER), 
        tywx.NotificationCenter.ignore(tywx.EventType.EVT_LOADING_DOWNLOAD_FINISH, this._onDownloadResFinish, this), 
        tywx.NotificationCenter.ignore(tywx.EventType.EVT_LOADING_DOWNLOAD_PROGRESS, this._onDownloadResProgress, this), 
        this.launchOption || (this.launchOption = !0, this.initOnShowHide(), wxapp.logic.share.initDefaultShare2()), 
        newfish.bilog.clickStat(newfish.bilog.clickStatEventType_AppStart_4), this.checkSceneInfoStartUp(function(e, t, o, n, i) {
            wxapp.model.sceneInfo.shareClick = n ? {
                shareId: n,
                shareUserId: i
            } : {
                shareId: 0,
                shareUserId: i
            }, newfish.InviteRoomId = o, wxapp.appData.firstLoadSuccess = !0, newfish.interface.enter({
                enterData: {
                    type: "game",
                    pluginParams: {
                        parentGameId: 9999
                    },
                    isOffline: 0,
                    supportIncUpdate: 0,
                    defaultRes: "",
                    iconUrl: "http://ddz.dl.tuyoo.com/cdn37/hall/plugin/img/zhaocaibuyu0421.png",
                    wxFishType: e,
                    roomId: t,
                    tableId: o
                }
            });
        }, function(e, t, i, a) {
            t && (wxapp.model.sceneInfo.shareClick = i ? {
                shareId: i,
                shareUserId: a
            } : {
                shareId: 0,
                shareUserId: a
            }), o ? (wxapp.model.sceneInfo.commitCacheParam(), wxapp.appData.firstLoadSuccess = !0, 
            newfish.interface.enter({
                enterData: {
                    type: "game",
                    pluginParams: {
                        parentGameId: 9999
                    },
                    isOffline: 0,
                    supportIncUpdate: 0,
                    defaultRes: "",
                    iconUrl: "http://ddz.dl.tuyoo.com/cdn37/hall/plugin/img/zhaocaibuyu0421.png",
                    wxFishType: 2,
                    roomId: n[0],
                    tableId: n[1]
                }
            })) : 1 == wxapp.appData.firstLoadCount ? newfish.interface.enter({
                enterData: {
                    type: "game",
                    pluginParams: {
                        parentGameId: 9999
                    },
                    isOffline: 0,
                    supportIncUpdate: 0,
                    defaultRes: "",
                    iconUrl: "http://ddz.dl.tuyoo.com/cdn37/hall/plugin/img/zhaocaibuyu0421.png",
                    wxFishType: e
                }
            }) : newfish.evtCenter.trigger(newfish.evts.EVT_STAGE_REPLACE, newfish.StageLoading);
        })));
    },
    startNext: function() {
        this.enterLobbyCount++, this.author && this.download && this.startNetwork();
    },
    initOnShowHide: function() {
        var e = this;
        wx.onShow(function(t) {
            cc.error("OnShow1"), tywx.StateInfo.isOnForeground = !0, tywx.NotificationCenter.trigger(tywx.EventType.GAME_SHOW, t), 
            setTimeout(function() {
                wx.setKeepScreenOn({
                    keepScreenOn: !0,
                    success: function() {},
                    fail: function() {}
                });
            }, 100), setTimeout(function() {
                newfish.audio._music && newfish.platformConvert.playMusicForSetting();
            }, 100), wxapp.model.sceneInfo.printInfo(), wxapp.appData.stateInfo.networkConnected && (e.checkSceneInfo(), 
            cc.error("OnShow2"));
        }), wx.onHide(function() {
            cc.error("OnHide1"), tywx.StateInfo.isOnForeground = !1, tywx.NotificationCenter.trigger(tywx.EventType.GAME_HIDE), 
            cc.error("OnHide2");
        });
    },
    checkSceneInfoStartUp: function(e, t) {
        wxapp.model.sceneInfo.printInfo();
        var o = wxapp.model.sceneInfo.getCacheParam();
        null != o && 2 == o.query.fishType && o.query.inviteCode != wxapp.appData.userInfo.userId ? (wxapp.model.sceneInfo.commitCacheParam(), 
        wxapp.twarn("app", "名片处理,渔场", "roomId", o.query.roomId, "tableId", o.query.tableId), 
        e && e(2, o.query.roomId, o.query.tableId, o.query.fishShareId, o.query.inviteCode)) : null != o && 1 == o.query.fishType && o.query.inviteCode != wxapp.appData.userInfo.userId ? (wxapp.model.sceneInfo.commitCacheParam(), 
        wxapp.twarn("app", "名片处理,大厅"), t && t(1, !0, o.query.fishShareId, o.query.inviteCode)) : (wxapp.model.sceneInfo.commitCacheParam(), 
        t && t(1, !1));
    },
    checkSceneInfo: function() {
        if (wxapp.model.sceneInfo.printInfo(), !wxapp.appData.stateInfo.networkConnected) return !1;
        if (!this.login_ok) return !1;
        var e = wxapp.model.sceneInfo.getCacheParam();
        return null != e && 2 == e.query.fishType && e.query.inviteCode != wxapp.appData.userInfo.userId && 0 == newfish.model.table.roomId && 0 == newfish.model.table.tableId ? (wxapp.model.sceneInfo.commitCacheParam(), 
        newfish.InviteRoomId = e.query.tableId, wxapp.twarn("app", "share进入game!!!!!!!!", "roomId", e.query.roomId, "tableId", e.query.tableId), 
        tywx.NotificationCenter.trigger(tywx.EventType.EVT_SHARE_ENTER_FISHROOM, e.query.roomId, e.query.tableId), 
        !0) : (null == e || 2 != e.query.fishType || e.query.inviteCode == wxapp.appData.userInfo.userId) && (wxapp.model.sceneInfo.commitCacheParam(), 
        !1);
    },
    checkWxVersion: function() {
        function e(e) {
            for (var t = (e = e.toString()).split("."), o = [ "", "0", "00", "000", "0000", "00000" ].reverse(), n = 0; n < t.length; n++) {
                var i = t[n].length;
                t[n] = o[i] + t[n];
            }
            return t.join("");
        }
        var t = wxapp.appData.wxSdkVersion, o = wx.getSystemInfoSync();
        if (o.system.toLocaleLowerCase().indexOf("android") < 0 ? wxapp.appData.appOs = "ios" : wxapp.appData.appOs = "android", 
        !function(t, o) {
            var n = e(t), i = e(o);
            return n == i || !(n > i);
        }(t, o.SDKVersion)) {
            return function e() {
                wxapp.tools.wxShowModal.show("微信版本过低, 升级微信到最新版才能愉快的捕鱼.", {
                    content: !1
                }, function() {
                    e();
                });
            }(), !1;
        }
        return !0;
    },
    resetDesignSize: function() {
        var e = cc.view.getFrameSize();
        if (e.height / e.width > 9 / 16) var t = (n = 1136) / e.width, o = Math.round(e.height * t); else var t = (o = 640) / e.height, n = Math.round(e.width * t);
        cc.view.setDesignResolutionSize(n, o, cc.ResolutionPolicy.SHOW_ALL);
    },
    setDevicePixelRatio: function() {
        var e = function() {
            cc.ContainerStrategy.prototype._setupContainer = function(e, t, o) {
                console.error("low");
                var n = cc.game.canvas, i = cc.game.container;
                window.wx || cc.sys.os !== cc.sys.OS_ANDROID || (document.body.style.width = (e._isRotated ? o : t) + "px", 
                document.body.style.height = (e._isRotated ? t : o) + "px"), i.style.width = n.style.width = t + "px", 
                i.style.height = n.style.height = o + "px";
                var a = e._devicePixelRatio = 1;
                e.isRetinaEnabled() && (a = e._devicePixelRatio = Math.min(2, window.devicePixelRatio || 1)), 
                n.width = t * a, n.height = o * a, cc._renderContext.resetCache && cc._renderContext.resetCache();
            }, cc.view.enableRetina(!0), wxapp.logic.appCenter.resetDesignSize();
        }, t = function() {
            cc.ContainerStrategy.prototype._setupContainer = function(e, t, o) {
                console.error("high");
                var n = cc.game.canvas, i = cc.game.container;
                window.wx || cc.sys.os !== cc.sys.OS_ANDROID || (document.body.style.width = (e._isRotated ? o : t) + "px", 
                document.body.style.height = (e._isRotated ? t : o) + "px"), i.style.width = n.style.width = t + "px", 
                i.style.height = n.style.height = o + "px";
                var a = e._devicePixelRatio = 1;
                e.isRetinaEnabled() && (a = e._devicePixelRatio = window.devicePixelRatio || 1), 
                n.width = t * a, n.height = o * a, cc._renderContext.resetCache && cc._renderContext.resetCache();
            }, cc.view.enableRetina(!0), wxapp.logic.appCenter.resetDesignSize();
        };
        !function() {
            var o = cc.sys.localStorage.getItem("newfish_setting_quality") || "1";
            o = parseInt(o), "ios" == wxapp.appData.appOs ? t() : o ? t() : e();
        }();
    }
};